module WapHelper  
  def ge_date
    Time.now.strftime("%m-%d")
  end

  #sid
  def my_sid
    if cookies[:sid].nil?
      @sid = request.params[:sid]
    else
      @sid = cookies[:sid]
    end
    return @sid
  end
  
  #click_num
  def my_cn    
    @cn = request.params[:cn]
    return @cn
  end
  
  def get_sections channel
    #查询栏目，有级别控制
    host = request.domain
    le = $level_map[host.swapcase]
    col_l = le[:col_level]
    sections = Section.find :all ,
      :conditions =>  ["status=? and channel_id=? and level <= ?", 1, channel.id,col_l],
      :order => 'x,y asc'
    return sections
  end

  #专辑频道取栏目
  def get_sections_rand channel
    #查询栏目，有级别控制
    host = request.domain
    le = $level_map[host.swapcase]
    col_l = le[:col_level]
    sections = Section.find :all ,
      :conditions =>  ["status=? and channel_id=? and level <= ?", 1, channel.id,col_l],
      :order => 'rand()',
      :limit => '5'
    return sections
  end

  def get_res_by_channel channel
    #查询资源，有级别控制
    host = request.domain
    le = $level_map[host.swapcase]
    col_l = le[:col_level]
    resources = Resource.find :all,
      :conditions =>  ["status=? and channel_id=? and level <= ?", 1, channel.id,col_l],
      :order => 'rand()',
      :limit => '3'
    return resources
  end

  def get_section_res section_id
    @res = Resource.find  :all , :conditions =>  ["status=? and col_id=? ", 1, section_id], :order => 'orders asc'
  end

  #热门标签
  def get_hot_series
    res_tags = ResTag.find_by_sql("select count(*) as ac,tag_id from res_tags group by tag_id order by ac desc limit 3")
    str = ""
    res_tags.each do |rt|
      str = rt.tag_id.to_s+","+str
    end
    str = str[0,(str.length - 1)]
    @hots_series = Tag.find_by_sql("select * from tags where id in (#{str})")
  end
end
